using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication11.Models.Mapping
{
    public class nodeMap : EntityTypeConfiguration<node>
    {
        public nodeMap()
        {
            // Primary Key
            this.HasKey(t => t.node_id);

            // Properties
            this.Property(t => t.node_name)
                .IsRequired()
                .HasMaxLength(64);

            this.Property(t => t.node_contact_phone)
                .HasMaxLength(32);

            this.Property(t => t.node_desc)
                .HasMaxLength(1024);

            this.Property(t => t.node_manager)
                .HasMaxLength(20);

            this.Property(t => t.node_name_en_US)
                .HasMaxLength(64);

            // Table & Column Mappings
            this.ToTable("node");
            this.Property(t => t.node_id).HasColumnName("node_id");
            this.Property(t => t.node_name).HasColumnName("node_name");
            this.Property(t => t.node_contact_phone).HasColumnName("node_contact_phone");
            this.Property(t => t.node_desc).HasColumnName("node_desc");
            this.Property(t => t.node_manager).HasColumnName("node_manager");
            this.Property(t => t.parent_node_id).HasColumnName("parent_node_id");
            this.Property(t => t.node_type).HasColumnName("node_type");
            this.Property(t => t.node_level).HasColumnName("node_level");
            this.Property(t => t.node_name_en_US).HasColumnName("node_name!en-US");

            // Relationships
            this.HasRequired(t => t.node2)
                .WithMany(t => t.node1)
                .HasForeignKey(d => d.parent_node_id);

        }
    }
}
